package com.cyh;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;

@MyAnnotation02
@MyAnnotation03(name2 = "cyh", schools = {"一中","二中"}) //name用的是默认值。
@MyAnnotation04("value值1")
public class Test02 {
    @MyAnnotation01
    @MyAnnotation02
    @MyAnnotation03(name = "c0", name2 = "c1")
    @MyAnnotation04(value = "value值2")
    public void testO1() {

    }

    public static void main(String arg[]) throws ClassNotFoundException, NoSuchFieldException {
        Class cl = Class.forName("com.cyh.Student");
        //获取所有注解
        Annotation[] annotations = cl.getAnnotations();
        for(Annotation annotation : annotations) {
            System.out.println(annotation);
        }
        //获取指定注解
        Tablekuang tablekuang = (Tablekuang) cl.getAnnotation(Tablekuang.class);
        String value = tablekuang.value();
        System.out.println(value);

        //获得类指定的注解
        Field f = cl.getDeclaredField("id");
        Fieldkuang annotation = f.getAnnotation(Fieldkuang.class);
        System.out.println(annotation.columnName());
        System.out.println(annotation.type());
        System.out.println(annotation.length());
    }
}
